﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Butterfly.Library.Components.Providers;
using System.Data;
using Butterfly.User.Library.Components.ib_User;
using Butterfly.User.Library.Components.ib_UserRole;

namespace Butterfly.User.Library.Providers
{
    public abstract class DataProvider
    {

        private static DataProvider objProvider;
        public static DataProvider Instance()
        {
            if (objProvider == null)
            {
                DataAccessProviderConfiguration objConfig = DataAccessProviderConfiguration.GetDataAccessProviderConfiguration();
                Provider defaultProvider = (Provider)objConfig.Providers[objConfig.DefaultProvider];
                Provider provider = new Provider(defaultProvider.ProviderName, defaultProvider.ProviderType, defaultProvider.ConnectionString);
                objProvider = (DataProvider)DataAccessProviderFactory.CreateDataAccess(provider);
            }
            return objProvider;
        }

        public static DataProvider Instance(string nameConnectionString)
        {
            if (objProvider == null)
            {
                DataAccessProviderConfiguration objConfig = DataAccessProviderConfiguration.GetDataAccessProviderConfiguration();
                Provider defaultProvider = (Provider)objConfig.Providers[nameConnectionString];
                Provider provider = new Provider(defaultProvider.ProviderName, "Butterfly.User.Library.Providers." + defaultProvider.ProviderType, defaultProvider.ConnectionString);
                objProvider = (DataProvider)DataAccessProviderFactory.CreateDataAccess(provider);
            }
            return objProvider;
        }

        // User
        public abstract IDataReader User_GetAll();

        public abstract IDataReader User_GetInfoByUsername(string _username);

        public abstract IDataReader User_GetInfoByUserId(int _userId);

        public abstract void User_Insert(ib_UserInfo objUser);

        public abstract void User_Update(ib_UserInfo objUser);

        public abstract void User_Delete(int _userId);

        // User Role

        public abstract IDataReader UserRole_GetAll();

        public abstract IDataReader UserRole_GetInfo(int _userRoleId);

        public abstract void UserRole_Insert(ib_UserRoleInfo objUserRole);

        public abstract void UserRole_Update(ib_UserRoleInfo objUserRole);

        public abstract void UserRole_Delete(int _userRoleId);
    }
}
